package org.example.user.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.common.result.Result;
import org.example.user.dto.req.UserLoginReqDTO;
import org.example.user.dto.req.UserLogoutReqDTO;
import org.example.user.dto.req.UserRegisterReqDTO;
import org.example.user.dto.resp.UserLoginRespDTO;
import org.example.user.dto.resp.UserLogoutRespDTO;
import org.example.user.dto.resp.UserRegisterRespDTO;
import org.example.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@Api(tags = "用户模块")
public class UserController {
    @Autowired
    UserService userService;

    @GetMapping("/login")
    @ApiOperation(value = "登录")
    public Result<UserLoginRespDTO> login(@RequestBody UserLoginReqDTO userLoginReqDTO){
       return Result.success(userService.login(userLoginReqDTO));
    }

    @GetMapping("/logout")
    @ApiOperation(value = "注销登录")
    public Result<UserLogoutRespDTO> logout(@RequestBody UserLogoutReqDTO userLogoutReqDTO){
        return Result.success(userService.logout(userLogoutReqDTO));
    }

    @PostMapping
    @ApiOperation(value = "注册用户")
    public Result<UserRegisterRespDTO> register(@RequestBody UserRegisterReqDTO userRegisterReqDTO){
        return Result.success(userService.register(userRegisterReqDTO));
    }
}
